/*
 厦门大学计算机专业 | 华为开发专家(HDE)
 专注《零基础学编程系列》  http://lblbc.cn/blog
 包含：鸿蒙 | Java | 安卓 | 前端 | Flutter | iOS | 小程序
 公众号：蓝不蓝编程
 */
import SwiftUI

struct ContentView: View {
    @State private var num1: String = "0"
    @State private var num2: String = "0"
    @State private var num3: String = "0"
    @State private var num4: String = "0"
    @State private var num5: String = "0"
    @State private var num6: String = "0"
    @State private var num7: String = "0"
    
    var body: some View {
        VStack {
            HStack(spacing: 10) {
                Text(num1)
                    .font(.system(size: 16))
                    .frame(width: 40, height: 40)
                    .overlay(RoundedRectangle(cornerRadius: 20)
                        .stroke(Color.gray, lineWidth: 1))
                    .padding(2)
                Text(num2)
                    .font(.system(size: 16))
                    .frame(width: 40, height: 40)
                    .overlay(RoundedRectangle(cornerRadius: 20)
                        .stroke(Color.gray, lineWidth: 1))
                    .padding(2)
                Text(num3)
                    .font(.system(size: 16))
                    .frame(width: 40, height: 40)
                    .overlay(RoundedRectangle(cornerRadius: 20)
                        .stroke(Color.gray, lineWidth: 1))
                    .padding(2)
                Text(num4)
                    .font(.system(size: 16))
                    .frame(width: 40, height: 40)
                    .overlay(RoundedRectangle(cornerRadius: 20)
                        .stroke(Color.gray, lineWidth: 1))
                    .padding(2)
                Text(num5)
                    .font(.system(size: 16))
                    .frame(width: 40, height: 40)
                    .overlay(RoundedRectangle(cornerRadius: 20)
                        .stroke(Color.gray, lineWidth: 1))
                    .padding(2)
                Text(num6)
                    .font(.system(size: 16))
                    .frame(width: 40, height: 40)
                    .overlay(RoundedRectangle(cornerRadius: 20)
                        .stroke(Color.gray, lineWidth: 1))
                    .padding(2)
                Text(num7)
                    .font(.system(size: 16))
                    .frame(width: 40, height: 40)
                    .overlay(RoundedRectangle(cornerRadius: 20)
                        .stroke(Color.gray, lineWidth: 1))
                    .padding(2)
            }
            
            Button("生成") {
                generateNumbers()
            }
            .frame(width: 100, height: 50)
            .background(
                RoundedRectangle(cornerRadius: 25)
                    .fill(Color.blue)
            )
            .foregroundColor(.white)
            .padding(.top, 50)
        }
    }
    
    private func generateNumbers() {
        let numbers = Array(1...33).shuffled()
        num1 = String(numbers[0])
        num2 = String(numbers[1])
        num3 = String(numbers[2])
        num4 = String(numbers[3])
        num5 = String(numbers[4])
        num6 = String(numbers[5])
        num7 = String(random(16))
    }
    
    private func random(_ max: Int) -> Int {
        return Int.random(in: 1...max)
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
